// Task 函子

const fs = require('fs')
const { task } = require('folktale/concurrency/task')
const { split, find } = require('lodash/fp')

function readFile (filename){
    // task(computation: any): Task

    return task(({reject, resolve}) => {
        fs.readFile(filename, 'utf-8', (error,data)=>{
            if(error) return reject(error)
            return resolve(data)
        })
    });
}


readFile('package.json')
    .map(split('\n'))
    .map(find(v=>v.includes('author')))
    .run()
    .listen({
        onReject: error=> {
            console.log('reject', error)
        },
        onResolved: data =>{
            console.log('resolve', data)
        }
    })


